<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class TimetableStoreRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $method = request()->method();

        $rules = [
            'name'       => 'string',
            'start_time' => 'date_format:H:i',
            'end_time'   => 'date_format:H:i',
        ];

        if ($method === 'POST') {
            $fields = ['name' , 'start_time' , 'end_time'];
            foreach ($fields as $field) {
                $rules[$field] = $rules[$field]. '|required';
            }
        }

        return $rules;
    }
}
